import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';

import { User } from '@/modules/app/entities';
import { ApiHideProperty } from '@nestjs/swagger';
import { IsNumber, isNumber, IsString } from 'class-validator';

/**
 * * 留言表
 */
@Entity('messages')
export class Message {
  @PrimaryGeneratedColumn('increment')
  messageId: number;

  /**
   * 内容
   */
  @IsString()
  @Column({ type: 'text' })
  content: string;

  @IsNumber()
  @Column({ nullable: true })
  userId: number;

  @ApiHideProperty()
  @ManyToOne(() => User, (user) => user.messages, {
    onDelete: 'CASCADE',
  })
  @JoinColumn({ name: 'userId' })
  user?: User;

  @CreateDateColumn()
  createdAt?: Date;

  @ApiHideProperty()
  @Column({ default: false, select: false })
  isDeleted?: boolean;
}
